package com.wzq.controller.pc;

import com.wzq.dao.pojo.Code;
import com.wzq.dao.pojo.Notice;
import com.wzq.dao.pojo.Result;
import com.wzq.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yzc
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/PC/notice")
public class PCNoticeController {

    @Autowired
    private INoticeService iNoticeService;
    //   添加
    @PostMapping
    public Result save(@RequestBody Notice notice) {
        boolean flag = iNoticeService.save(notice);
        return new Result(flag ? Code.SAVE_OK:Code.SAVE_ERR,flag);
    }
    //   修改
    @PutMapping
    public Result update(@RequestBody Notice notice) {
        boolean flag = iNoticeService.updateById(notice);
        return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag);
    }

    //    id删除
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        boolean flag = iNoticeService.removeById(id);
        return new Result(flag ? Code.DELETE_OK:Code.DELETE_ERR,flag);
    }

    //     获得所有用户信息
    @GetMapping
    public Result getAll() {
        List<Notice> list = iNoticeService.list();
        Integer code = list != null ? Code.GET_OK : Code.GET_ERR;
        String msg = list != null ? "" : "数据查询失败，请重试！";
        return new Result(code,list,msg);
    }

}
